package com.bjc.nio;

import java.nio.IntBuffer;

/**
 * @program: nettypro
 * @description: NIO
 * @author: bjc
 * @create: 2021-09-02 21:26
 */
public class BasicBuffer {

    public static void main(String[] args) {
        //创建一个buffer 大小为5 即可以存放5个int
        IntBuffer intBuffer = IntBuffer.allocate(5);

        for (int i = 0; i < intBuffer.capacity(); i++) {
            intBuffer.put(i*2);
        }

        //如何从buffer读取数据
        //将buffer转换 读写切换！！！！
        intBuffer.flip();
        //调整起点位置
//        intBuffer.position(2);
        //调整buffer大小
//        intBuffer.limit(3);
        while (intBuffer.hasRemaining()){
            System.out.println(intBuffer.get());
        }
    }
}
